<template>
    <div>
        <h3>医生信息显示</h3>
        <div>
            名称<input type="text" v-model="arr.Name" />
            职称 <select v-model="arr.DoctorZhiCheng">
                <option value="">请选择</option>
                <option value="主治医师">主治医师</option>
                <option value="护士">护士</option>
                <option value="护士长">护士长</option>
            </select>
            <input type="button" value="查询" @click="Show" class="btn btn-info" />
        </div>
        <table class="table table-bordered">
            <tbody>
                <tr>
                    <td align="right">医生</td>
                    <td align="right">科室</td>
                    <td align="right">职称</td>
                    <td align="right">第一执业医师</td>
                    <td align="right">是否开通账号</td>
                    <td align="right">图片</td>
                    <td align="right">操作</td>
                </tr>
                <tr v-for="item in brr.list" :key="item.doctorId">
                    <td align="right">{{ item.doctorName }}</td>
                    <td align="right">{{ item.keShiName }}</td>
                    <td align="right">{{ item.doctorZhiCheng }}</td>
                    <td align="right">{{ item.doctorYiYuan }}</td>
                    <td align="right">{{ item.shiFou == true ? '启用' : '禁用' }}</td>
                    <td align="right"> <img :src="item.ddctorType" width="60" height="60" /></td>
                    <td align="right"><input type="button" value="编辑" @click="Up(item.doctorId)" class="btn btn-info" />

                        <input type="button" value="删除" @click="Del(item.doctorId)" class="btn btn-info" />
                    </td>
                </tr>
            </tbody>
        </table>
        <div>
            共<span style="color: red;">{{ brr.totalPage }}</span>页
            共<span style="color: red;">{{ brr.totalCount }}</span>条
            <span style="color: red;">{{ arr.PageIndex }}</span>/<span style="color: red;">{{ brr.totalPage }}</span>
            <input type="button" value="首页" @click="Page(1)" class="btn btn-info" />
            <input type="button" value="上一页" @click="Page(arr.PageIndex - 1)" class="btn btn-info" />
            <input type="button" value="下一页" @click="Page(arr.PageIndex + 1)" class="btn btn-info" />
            <input type="button" value="尾页" @click="Page(brr.totalPage)" class="btn btn-info" />
        </div>
    </div>
</template>

<script setup lang="ts">
import { reactive, ref, onMounted } from 'vue';
import axios from 'axios';
import { useRoute, useRouter } from 'vue-router';

let arr: any = ref({
    PageIndex: 1,
    PageSize: 2,
    Name: "",
    DoctorZhiCheng: ""
})
let brr: any = ref({
    "totalPage": '',
    "totalCount": '',
    "list": []
})
onMounted(() => {
    Show();
})
const Show = () => {
    axios({
        url: "https://localhost:7107/api/Doctor/Show",
        params: arr.value,
        method: "get"
    })
        .then(res => {
            brr.value = res.data;
            console.log(brr.value);

        })
}

const Page = (num: any) => {
    if (num < 1) {
        num = 1;
    }
    if (num > brr.value.totalPage) {
        num = brr.value.totalPage;
    }

    arr.value.PageIndex = num;
    Show();
}

let use = useRouter();


const Up = (id: any) => {
    use.push({
        path: "/DoctorUp",
        query: { id: id }
    })
}
const Del = (id: any) => {
    let a = confirm('确认删除么？')
    if (a) {


        axios({
            url: "https://localhost:7107/api/Doctor/DoctorDel",
            params: { id: id },
            method: "delete"
        })
            .then(res => {
                if (res.data > 0) {
                    alert('删除成功');
                    Show();
                }
                else {
                    alert('删除失败');
                }
            })
    }
}

</script>

<style scoped>
span {
    padding: 15px 15px;
}
</style>